package com.screen.screendisplay.service.impl.al;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.screen.screendisplay.entity.al.AlOverviewItem;
import com.screen.screendisplay.mapper.al.AlOverviewItemMapper;
import com.screen.screendisplay.service.al.AlOverviewItemService;
import com.screen.screendisplay.vo.al.AlOverviewTechIndicatorsVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 指标概览表 服务实现类
 * </p>
 *
 * @author xuesong
 * @since 2025-08-23
 */
@Service
public class AlOverviewItemServiceImpl extends ServiceImpl<AlOverviewItemMapper, AlOverviewItem> implements AlOverviewItemService {

    @Override
    public AlOverviewTechIndicatorsVO getLatestTechIndicators() {
        // 查询最新的一条记录（按年月日倒序）
        QueryWrapper<AlOverviewItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("year", "month", "day");
        queryWrapper.last("LIMIT 1");
        
        AlOverviewItem latestItem = baseMapper.selectOne(queryWrapper);
        
        // 如果没有数据，返回空对象
        if (latestItem == null) {
            return new AlOverviewTechIndicatorsVO();
        }
        
        // 转换为VO对象
        AlOverviewTechIndicatorsVO vo = new AlOverviewTechIndicatorsVO();
        vo.setAlProductionYearly(latestItem.getAlProductionYearly());
        vo.setAlCapacityYearly(latestItem.getAlCapacityYearly());
        vo.setCarbonProductionYearly(latestItem.getCarbonProductionYearly());
        vo.setCarbonCapacityYearly(latestItem.getCarbonCapacityYearly());
        vo.setAlCapacityUtilization(latestItem.getAlCapacityUtilization());
        vo.setAlSalesYearly(latestItem.getAlSalesYearly());
        vo.setAlWaterConversionRate(latestItem.getAlWaterConversionRate());
        
        return vo;
    }

}
